package com.tranq;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class TrafficStatReducer extends Reducer<Text, TrafficStatRecord, Text, TrafficStatRecord> {

    public void reduce(Text key, Iterable<TrafficStatRecord> values, Context context) throws IOException, InterruptedException {
        int up = 0, down = 0, total=0;
        for (TrafficStatRecord val : values) {
            up += val.get(0);
            down += val.get(1);
            total += val.get(2);
        }
        context.write(key, new TrafficStatRecord(up, down, total));
    }
}
